'''
Author: your name
Date: 2020-10-30 10:48:40
LastEditTime: 2020-10-30 11:30:36
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \python-study\爬虫学习\爬取网页.py
'''
import urllib.request
import urllib.parse
import json

if __name__=="__main__":
    # response = urllib.request.urlopen("http://www.baidu.com")
    # print(response)
    url="http://www.baidu.com"
    dic = {'name':'melon','age':18}
    data = urllib.parse.urlencode(dic)
    user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
    headers = { 'User-Agent' : user_agent }
    req = urllib.request.Request('http://www.baidu.com', data.encode(),headers)
    opener = urllib.request.urlopen(req)
    print(opener.read())